//
//  SISSEscrowAccountStartViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/12/25.
//  Copyright © 2018 优房网. All rights reserved.
//

#import "SISSEscrowAccountStartViewController.h"
#import "SISSEscrowAccountApplyViewController.h"
#import "SISSChooseView.h"
#import "SISSPickerView.h"


@interface SISSEscrowAccountStartViewController ()<SISSChooseViewDelegate>

///
@property (weak, nonatomic) SISSChooseView *chooseView;
/// 确定按钮
@property (weak, nonatomic) UIButton *nextButton;

///
@property (assign, nonatomic) NSInteger chooseIndex;

@end

@implementation SISSEscrowAccountStartViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"监管账户申请";
    self.chooseIndex = 0;
}



- (void)nextButtonClickAction {
    if (self.chooseView.rightStr.length == 0) {
        [SISSTools showSVErrorTitle:@"请选择监管银行" andTime:2 andColor:YES];
        return;
    }
    SISSEscrowAccountApplyViewController *vc = [[SISSEscrowAccountApplyViewController alloc] init];
    vc.houseProgressModel = self.houseProgressModel;
    vc.houseProgressRecordInfoModel = self.houseProgressRecordInfoModel;
    vc.passengerProgressModel = self.passengerProgressModel;
    vc.passengerProgressRecordInfoModel = self.passengerProgressRecordInfoModel;
    SISSEscrowAccountInfoModel *escrowAccountInfoModel = [[SISSEscrowAccountInfoModel alloc] init];
    escrowAccountInfoModel.bank = self.chooseView.rightStr;
    vc.escrowAccountInfoModel = escrowAccountInfoModel;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - SISSChooseViewDelegate
- (void)clickChooseActionWithChooseView:(SISSChooseView *)chooseView {
    SISSPickerView *pickerView = [[SISSPickerView alloc] initWithFrame:self.view.bounds];
    pickerView.title = @"监管银行";
    pickerView.titleArray = @[@"建设银行"];
    pickerView.isArea = NO;
    pickerView.firstIndex = self.chooseIndex;
    __weak typeof(self) weakself = self;
    pickerView.completion = ^(NSString *firstTitle, NSString *secondTitle, NSInteger firstIndex, NSInteger secondIndex) {
        weakself.chooseView.rightStr = firstTitle;
        weakself.chooseIndex = firstIndex;
    };
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    SISSChooseView *chooseView = [[SISSChooseView alloc] init];
    chooseView.leftStr = @"监管银行";
    chooseView.rightPlaceStr = @"请选择建设银行";
    chooseView.delegate = self;
    [self.view addSubview:chooseView];
    self.chooseView = chooseView;
    
    UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [nextButton setTitle:@"下一步" forState:UIControlStateNormal];
    [nextButton setBackgroundColor:MAIN_COLOR];
    [nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [nextButton addTarget:self action:@selector(nextButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    nextButton.layer.cornerRadius = 4;
    nextButton.layer.masksToBounds = YES;
    [self.view addSubview:nextButton];
    self.nextButton = nextButton;
    
    
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    [self.chooseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_topLayoutGuideBottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(5.5 * globelMargin);
    }];
    
    [self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.chooseView.mas_bottom).offset(6 * globelMargin);
        make.centerX.equalTo(weakSelf.view);
        make.width.mas_equalTo(SCREEN_WIDTH * 0.7);
        make.height.mas_equalTo(44);
    }];
}

@end
